<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="net.sf.rose.business.service.DBMetaService" %>
<%@include file="/common/header.jsp"%>
<c:set var="path" value="..${ctx}/define/actionunit"/>

<div class="pageContent">

	<div class="panelBar">
		<ul class="toolBar">
			<li><a class="edit" onclick="save();" title="保存"><span>保存</span></a></li>
			<li class="line">line</li>
			<li><a class="delete" onclick="deleteAction();"><span>删除</span></a></li>
		</ul>
	</div>

	<form name="form" method="post" action="${path}/save.html" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone);">
		<input type="hidden" id="actionType" name="actionType" value="${actionType}" />
		<div class="pageFormContent" layoutH="260">
			<fieldset>
				<legend>基本信息</legend>
				<dl >
					<dt>操作单元名称：</dt>
					<dd><input name="name" id="bean_name" type="text" size="30" value="${bean.name}" class="required" /></dd>
				</dl>
				<dl >
					<dt>分类：</dt>
					<dd><input name="sort" type="text" size="30" value="${bean.sort}" class="required" /></dd>
				</dl>
				<dl >
					<dt>起用缓存：</dt>
					<dd>
						<select class="combox" name="cache">
							<option value="0" <c:if test="${bean.cache}">selected</c:if> >不用</option>
							<option value="1" <c:if test="${bean.cache}">selected</c:if> >使用</option>
						</select>
					</dd>
				</dl>
				<dl class="nowrap">
					<dt>SQL文：</dt>
					<dd><textarea name="sql" cols="90" rows="5" class="required"><c:out value="${bean.sql}" /></textarea></dd>
				</dl>
				<dl class="nowrap">
					<dt>描述：</dt>
					<dd><textarea name="description" cols="90" rows="4">${bean.description}</textarea></dd>
				</dl>
			</fieldset>
		</div>

		<div class="pageFormContent" layoutH="160">
		<div class="tabs">
			<div class="tabsHeader">
				<div class="tabsHeaderContent">
					<ul>
						<li class="selected"><a href="javascript:void(0)"><span>查询参数列表</span></a></li>
					</ul>
				</div>
			</div>
			<div class="tabsContent" style="height:160px;">
				<div>
					<table class="list nowrap itemDetail" addButton="添加参数" width="100%">
						<thead>
							<tr>
								<th type="text" name="items.fieldName[#index#]" size="20" fieldClass="required">数据库字段名</th>
								<th type="text" name="items.searchName[#index#]" size="20" fieldClass="required">查询语句字段名</th>
								<th type="text" name="items.replaceName[#index#]" size="20" fieldClass="required">替换查询语句</th>
								<th type="enum" name="items.type[#index#]" enumUrl="..${ctx}/common/view.html?jsp=define/dbmeta/data_type_list" size="23" fieldClass="required">数据类型</th>
								<th type="text" name="items.format[#index#]" size="10">格式</th>
								<th type="text" name="items.defaultValue[#index#]" size="10">默认值</th>
								<th type="enum" name="items.force[#index#]" enumUrl="..${ctx}/common/view.html?jsp=base/com/yes_no_list" size="2" >强制</th>
								<th type="del" width="30">操作</th>
							</tr>
						</thead>
						<tbody>
							<c:if test="${! empty bean.paramenters }">
							<c:forEach var="data" items="${bean.paramenters}" varStatus="status">
							<tr>
								<td><input type="text" class="required textInput" size="20" value="${data.fieldName}" name="items.fieldName[${status.index}]" /></td>
								<td><input type="text" class="required textInput" size="20" value="${data.searchName}" name="items.searchName[${status.index}]" /></td>
								<td><input type="text" class="required textInput" size="20" value="${data.replaceName}" name="items.replaceName[${status.index}]" /></td>
								<td>
									<select name="items.type[${status.index}]" class="combox">
										<%request.setAttribute("dataTypes", DBMetaService.getService().getAllDataType());%>
										<c:forEach var="type" items="${dataTypes}">
											<option value="${type}" <c:if test="${type==data.type}">selected</c:if> >${type}</option>
										</c:forEach>
									</select>
								</td>
								<td><input type="text" class="textInput" size="10" value="${data.format}" name="items.format[${status.index}]" /></td>
								<td><input type="text" class="textInput" size="10" value="${data.defaultValue}" name="items.defaultValue[${status.index}]" /></td>
								<td>
									<select name="items.force[${status.index}]" class="combox">
										<option value="1" <c:if test="${data.force}">selected</c:if> >是</option>
										<option value="0" <c:if test="${!data.force}">selected</c:if> >否</option>
									</select>
								</td>
								<td><a class="btnDel " href="javascript:void(0)">删除</a></td>
							</tr>
							</c:forEach>
							</c:if>
						</tbody>
					</table>
				</div>
								
			</div>
			
			<div class="tabsFooter">
				<div class="tabsFooterContent"></div>
			</div>
		</div>

		</div>

	</form>
</div>
<script type="text/javascript">
/**
 * dialog上的表单提交回调函数
 * 服务器转回navTabId，可以重新载入指定的navTab. statusCode=DWZ.statusCode.ok表示操作成功, 自动关闭当前dialog
 * form提交后返回json数据结构,json格式和navTabAjaxDone一致
 */
function dialogAjaxDone(json){
	DWZ.ajaxDone(json);
	if (json.statusCode == DWZ.statusCode.ok){
		// alertMsg.correct(json.message);
		if(json.callbackType){
			var url = "${path}/list.html";
			navTab.reload(url,null,"base_define_action_unit_list");
			// navTab.reload(url);
			//navTab.reloadFlag("base_define_action_list"); // 下次切换到列表页签时需要刷新一下
			setTimeout(function(){$.pdialog.closeCurrent();}, 100); // 关闭此编辑页签
		}
	}
}

function save(){
	//$("#xxxId", $.pdialog.getCurrent());
	//alert($("#actionName").val());
	//alert($("#actionName", "base_define_action_unit_list").val());
	//alert($("#bean_name", $.pdialog.getCurrent()).val());
	//alert($.pdialog.getParent());
	$(form).submit();
}

function deleteAction(){
	var rel = '';
	$('.base_define_action_unit_list_tr').each(function(){
		if($(this).hasClass("selected")){
			rel = $(this).attr('rel');
		}
	});
	if(rel==''){
		alertMsg.warn('请先选择一条数据！');
	}else{
		alertMsg.confirm("确定要删除吗?", {
			okCall: function(){
				var arr = rel.split(","); //字符分割 
				var url = "${path}/delete.html?type=action&id=" + arr[1];
				$.ajax({
					type: "post", url: url,
					success: function(json){
						alertMsg.correct(json.msg);
						var url = "${path}/list.html";
						navTab.reload(url);
						setTimeout(function(){$.pdialog.closeCurrent();}, 100); // 关闭此编辑页签
					},
					error: function(){
						alertMsg.error('系统错误，请联系管理员！');
					}
				});
			}
		});
	}
}
</script>
